import React, {Component} from 'react'
import Mock from 'mockjs'
import moment from 'moment'


export const dataCalc=({
  showModal=false,
  jobInfo=null,
  errorDistribute=null,
  jobHistoryAll=[],
  jobHistory=[],
  records,
  jobList=[],
  location,
  })=>{

      const jobListData=jobList.map(item=>({
          name:item,
          value:item
      }))
      jobListData.unshift({
        name:'请选择',
        value:''
      })

      // 基础信息 数据
      const baseInfoData=[
        {
          name:'名称',
          value:jobInfo&&jobInfo.jobName||'-',
        },
        {
          name:'功能描述',
          value:jobInfo&&jobInfo.jobDescription||'-',
        },
        {
          name:'责任人',
          value:jobInfo&&jobInfo.jobKeeper||'-',
        },
        {
          name:'Crontab',
          value:jobInfo&&jobInfo.jobCrontab||'-',
        },
      ]

      // 出错分布 数据
      const errorData=errorDistribute&&errorDistribute.errorClass.map((item,i)=>({
        name:item,
        value:errorDistribute.errorDistribute[i]
      }))||[]

      // 执行记录 数据
      const failListData=jobHistory.length&&jobHistory.map((item,i)=>{
        return {
          key: i,
          id:item.id,
          startTime:item.startTime.split('.')[0],
          status:item.jobResult,
          location:item.location,
          endTime:item.endTime.split('.')[0],
          type:item.errorClass,
          suggest:item.advise
        }
      })||[]


      // 历史执行记录 数据
      let historyData=[
        {
          name:'运行时间',
          value:records&&records.execSummary&&records.execSummary.duration,
        },
        // {
        //   name:'处理数据量',
        //   value:records&&records.execSummary&&records.execSummary.recordCount,
        // },
        {
          name:'历史平均运行时间',
          value:records&&records.execSummary&&records.execSummary.durationAvg,
        },
        // {
        //   name:'历史平均处理数据量',
        //   value:records&&records.execSummary&&records.execSummary.recordCountAvg,
        // },
      ]


      // 错误详情 数据
      const errTip=records&&records.errorDetail||'-'

      // 检查详情（取数） 数据
      const valueData=records&&records.ETLCheckResult&&records.ETLCheckResult.length&&records.ETLCheckResult.map((item,i)=>({
        key: i,
        sourceSql: item.srcSQL,
        sourceNum: item.srcCount,
        targetNum: item.targetCount,
        targetSql:item.targetSQL,
      }))||[]

      // 检查详情（计算） 数据
      const calcData=records&&records.calcCheckResult&&records.calcCheckResult.length&&records.calcCheckResult.map((item,i)=>({
        key: i,
        expect: item.expectValue,
        actual: item.actualValue,
        content: item.diffReason,
      }))||[]

      // 处理记录 数据
      const recordData=records&&records.handleRecord&&records.handleRecord.length&&records.handleRecord.map((item,i)=>({
        key: i,
        name: item.person,
        date: item.time,
        result: item.result,
        content:item.content,
      }))||[]

      return {
        jobListData,
        baseInfoData,
        errorData,
        failListData,
        historyData,
        errTip,
        valueData,
        calcData,
        recordData,
      }

}
